package framework.bean;

import framework.constant.UriConst;

import java.util.Objects;

/**
 * @author 马洁
 * @date 2020/3/11 - 12:34
 */
public class NeedScanPackageBean {
    /**
     * 需要扫描的模块的名称
     */
    private String modelName;
    /**
     * 需要扫描的包的名称
     */
    private String packageName;

    public NeedScanPackageBean(String modelName, String packageName) {
        this.modelName = checkEndWithSlashElseAppend(modelName);
        this.packageName = checkEndWithSlashElseAppend(packageName);
    }

    public NeedScanPackageBean(String modelName) {
        this.modelName = checkEndWithSlashElseAppend(modelName);
    }


    public String getAllPackageName() {
        return modelName + packageName;
    }

    private String checkEndWithSlashElseAppend(String path) {
        return checkIsEndWithSlash(path) ?
                path :
                appendSlash(path);
    }

    private boolean checkIsEndWithSlash(String path) {
        return Objects.equals(path.lastIndexOf(UriConst.SPLICER), path.length() - 1);
    }

    private String appendSlash(String path) {
        return path + UriConst.SPLICER;
    }

    public String getModelName() {
        return modelName;
    }
}
